package com.ruibang.glass.common.utils;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @Author: songJinKang
 * @CreateTime: 2024-05-14  15:58
 * @Description: TODO
 * @Version: 1.0
 */
public class DateUtils {
    // 字符串转 LocalDateTime
    public static LocalDateTime stringToLocalDateTime(String strDateTime, String pattern) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
        return LocalDateTime.parse(strDateTime, formatter);
    }

    // LocalDateTime 转字符串
    public static String localDateTimeToString(LocalDateTime localDateTime, String pattern) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
        return localDateTime.format(formatter);
    }

    public static long calculateHourDifference(LocalDateTime startTime, LocalDateTime endTime) {
        Duration duration = Duration.between(startTime, endTime);
        return duration.toHours();
    }

}
